//
//  PAChargeMoneyView.m
//  PAMobileWallet
//
//  Created by Pay_SMP002 on 13-7-4.
//  Copyright (c) 2013年 平安付. All rights reserved.
//

#import "PAChargeMoneyView.h"
#import "PAChargeMoneyViewController.h"
#import "UIColor+Extend.h"
#import "PABaseView.h"

@implementation PAChargeMoneyView
@synthesize cardinfobgImage;

@synthesize cardlogoImage;
@synthesize cardNameLable;
@synthesize cardNumLable;
@synthesize secleteCardInfo;
@synthesize secleteCardInfoImage;

@synthesize moneyText;
@synthesize payPwdText;
@synthesize confirmButton;

@synthesize payMoneyImage;
@synthesize payPassImage;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        CGFloat x, y, w, h;
        
        //卡的信息的view
        x = 10;  y = 44 + 10;  w = 300;  h = 100/2;
        UIView * cardinfoView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        cardinfoView.backgroundColor = [UIColor clearColor];
        
        x = 0;  y = 0;  w = 300;  h = 100/2;
        cardinfobgImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        cardinfobgImage.backgroundColor = [UIColor clearColor];
        cardinfobgImage.image = [UIImage imageNamed:@"textbox2.png"];
        [cardinfoView addSubview:cardinfobgImage];

        x = 5;  y = (50 - 35)/2;  w = 100;  h = 70/2;
        cardlogoImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        cardlogoImage.backgroundColor = [UIColor clearColor];
        [cardinfoView addSubview:cardlogoImage];

        x = 100 + 20/2;  y = (50-30)/2;  w = 160;  h = 60/2;
        cardNumLable = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        cardNumLable.textColor = ENABLE_COLOR;
        cardNumLable.font = [UIFont boldSystemFontOfSize:16.0];
        cardNumLable.textAlignment = NSTextAlignmentCenter;
        cardNumLable.backgroundColor = [UIColor clearColor];
        [cardinfoView addSubview:cardNumLable];
        
        //后边箭头  imageview
        x = 100 + 10 + 160 + 10;  y = (50-20)/2 ;  w = 26/2;  h = 40/2;
        secleteCardInfoImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        secleteCardInfoImage.backgroundColor = [UIColor clearColor];
        secleteCardInfoImage.image = [UIImage imageNamed:@"card_chooseBT.png"];
        [cardinfoView addSubview:secleteCardInfoImage];

        //后边箭头 用一个大的button覆盖上去
        x = 0;  y = 0;  w = 300;  h = 100/2;
        secleteCardInfo = [UIButton buttonWithType:UIButtonTypeCustom];
        secleteCardInfo.frame = CGRectMake(x, y, w, h);
        secleteCardInfo.backgroundColor = [UIColor clearColor];
        [secleteCardInfo addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        secleteCardInfo.tag = 10;
        [cardinfoView addSubview:secleteCardInfo];
        
        [self addSubview:cardinfoView];
        
        x = 10;  y = 44 + 10 + 100/2 + 10;  w = 300;  h = 100/2;
        payMoneyImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        payMoneyImage.image = [UIImage imageNamed:@"textbox.png"];
        [self addSubview:payMoneyImage];

        x = 20;  y = 44 + 10 + 100/2 + 10;  w = 300-10-10;  h = 100/2;
        moneyText = [[UITextField alloc] initWithFrame:CGRectMake(x, y, w, h)];
        moneyText.keyboardType = UIKeyboardTypeDecimalPad;
        moneyText.borderStyle = UITextBorderStyleNone;
        moneyText.placeholder = @"金额";
        moneyText.secureTextEntry = NO; //密码
        moneyText.delegate = self;
        moneyText.contentHorizontalAlignment = NSTextAlignmentCenter;
        moneyText.contentVerticalAlignment = NSTextAlignmentLeft;
        moneyText.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
        moneyText.backgroundColor = [UIColor clearColor];
        [self addSubview:moneyText];

        x = 10;  y = 44 + 10 + 100/2 + 10 + 100/2 + 10;  w = 300;  h = 100/2;
        payPassImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        payPassImage.image = [UIImage imageNamed:@"textbox.png"];
        [self addSubview:payPassImage];

        x = 20;  y = 44 + 10 + 100/2 + 10 + 100/2 + 10;  w = 300-10-10;  h = 100/2;
        payPwdText = [[UITextField alloc] initWithFrame:CGRectMake(x, y, w, h)];
        payPwdText.delegate = self;
        payPwdText.keyboardType = UIKeyboardTypeASCIICapable;
        payPwdText.borderStyle = UITextBorderStyleNone;
        payPwdText.placeholder = @"支付密码";
        payPwdText.secureTextEntry = YES;
        payPwdText.contentHorizontalAlignment = NSTextAlignmentCenter;
        payPwdText.contentVerticalAlignment = NSTextAlignmentLeft;
        payPwdText.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
        payPwdText.backgroundColor = [UIColor clearColor];
        payPwdText.returnKeyType = UIReturnKeyDone;
        [self addSubview:payPwdText];

        x = 10;  y = 44 + 10 + 100/2 + 10 + 100/2 + 10 + 100/2 + 20;  w = 300;  h = 100/2;
        confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
        confirmButton.frame = CGRectMake(x, y, w, h);
        [confirmButton setBackgroundImage:[UIImage imageNamed:@"card_blank_1.png"] forState:UIControlStateNormal];
        confirmButton.titleLabel.textColor = [UIColor darkTextColor];;
        [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
        [confirmButton setBackgroundImage:[UIImage imageNamed:@"button_B1.png"] forState:UIControlStateNormal];
        confirmButton.titleLabel.textColor = ENABLE_COLOR;
        confirmButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
        [confirmButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        confirmButton.enabled = NO;
        confirmButton.tag = 20;
        [self addSubview:confirmButton];
    }
    return self;
}

-(void)buttonActive:(id)sender
{
    [self.parentController testNext:sender];
}

#pragma mark -
#pragma mark ========================================
#pragma mark UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField == moneyText) {
        payMoneyImage.image = [UIImage imageNamed:@"textbox2.png"];
        payPassImage.image = [UIImage imageNamed:@"textbox.png"];
    }else if (textField == payPwdText){
        payMoneyImage.image = [UIImage imageNamed:@"textbox.png"];
        payPassImage.image = [UIImage imageNamed:@"textbox2.png"];
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    //
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == moneyText)
    {
        [payPwdText becomeFirstResponder];
    }
    else if (textField == payPwdText)
    {
        [textField resignFirstResponder];
    }
    
    return YES;
}

@end
